//
//  RideViewController.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/11/27.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "RideViewController.h"
#import "RoutePlanningViewController.h"

@interface RideViewController () <RoutePlanningRideDelegate>

@property (nonatomic , strong) RoutePlanningViewController *routePlanningViewController;


@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
- (IBAction)loginBtnAction:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *tip;


@end

@implementation RideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLoginStatusNotificenter];
    
    if (USERINFOManager.getUserInfo.loginStatus == YES) {
        [self initRoute];
        self.loginBtn.hidden = YES;
    }else{
        self.loginBtn.hidden = NO;
    }
    
    self.tip.hidden = YES;
}

-(void)rideStatusFailer{
    self.tip.hidden = NO;
    [self.routePlanningViewController.view removeFromSuperview];
}

-(void)initRoute{
    
    if (self.routePlanningViewController == nil) {
        self.routePlanningViewController = (RoutePlanningViewController *)[RoutePlanningViewController getViewControllerFromSbName:@"RoutePlanning" viewControllerName:@"RoutePlanningViewController"];
    }
    
    self.routePlanningViewController.routePlanningStatus = RoutePlanningTicket;
    self.routePlanningViewController.delegate = self;
    self.routePlanningViewController.lineId = @"0";
    self.routePlanningViewController.view.frame = CGRectMake(0, 0, [UIScreen width], self.view.frame.size.height - 49);
    self.routePlanningViewController.rideViewController = self;
    [self.routePlanningViewController.view removeFromSuperview];
    [self.view addSubview:self.routePlanningViewController.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark --------登录状态回掉---------------
-(void)addLoginStatusNotificenter{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:LoginSuccess object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:LogoutSuccess object:nil];
}

-(void)removeLoginStatusNotificenter{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)loginSuccess{
    self.loginBtn.hidden = YES;
    [self initRoute];
}

-(void)logoutSuccess{
     self.loginBtn.hidden = NO;
    [self.routePlanningViewController.view removeFromSuperview];
}

- (IBAction)loginBtnAction:(UIButton *)sender {
    [self jumperLogin];
}
@end
